package com.xxxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxy.commonResult.CommonResultPage;
import com.xxxy.dao.CourseDao;
import com.xxxy.model.Course;
import com.xxxy.response.StudentResponse;
import com.xxxy.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sjh
 * @date 2022/2/9 10:03
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements CourseService {

    @Autowired
    CourseDao courseDao;

    @Override
    public CommonResultPage list(Integer page, Integer size, Integer facultyId) {
        PageHelper.startPage(page,size);
        LambdaQueryWrapper<Course> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(facultyId != 0){
            lambdaQueryWrapper.eq(Course::getFacultyId, facultyId);
        }
        List<Course> courseList = courseDao.selectList(lambdaQueryWrapper);
        PageInfo<Course> pageInfo = new PageInfo<>(courseList);
        CommonResultPage result = new CommonResultPage();
        result.setTotal(pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }
}
